import message from "./message.js";
const pay = {
	exePay: function(param) {
		return new Promise((resolve, reject) => {
			uni.requestPayment({
			    "provider": "wxpay", 
				timeStamp: param.timeStamp,
				nonceStr: param.nonceStr,
				package: param.packageVal,
				signType: param.signType,
				paySign: param.paySign,
			    success(res) {
					message.info("支付成功");
					resolve(res);
				},
			    fail(e) {
					message.info("支付失败");
				}
			});
		});
	},
	requestMerchantTransfer: function(targ) {
		return new Promise((resolve, reject) => {
			if (uni.canIUse("requestMerchantTransfer")) {
				uni.requestMerchantTransfer({
					mchId: targ.mid,
					appId: targ.appid,
					package: targ.packageInfo,
					success: res => {
						resolve(res);
					},
					fail: err => {
					}
				});
			} else {
				uni.showModal({
					content: '你的微信版本过低，请更新至最新版本。',
					showCancel: false,
				});
			}
		});
	}
};

export default pay;